package com.onetwork.core.domain;

import com.db4o.ObjectContainer;
import com.onetwork.core.resource.Resource;
import com.onetwork.core.resource.ResourceType;
import java.io.Serializable;

public class DB4ODomain implements Serializable {
    private static final long serialVersionUID = 1L;
    public DB4ODomain() {}
    
    public void save() {
        ObjectContainer objectContainer = Resource.get(ResourceType.Persistence);
        objectContainer.set(this);
        objectContainer.commit();
    }
    
    public void delete() {
        ObjectContainer objectContainer = Resource.get(ResourceType.Persistence);
        objectContainer.delete(this);
        objectContainer.commit();
    }
    
    public static <T> T findAll(Class<? extends DB4ODomain> clazz) {
        ObjectContainer objectContainer = Resource.get(ResourceType.Persistence);
        return (T)objectContainer.query(clazz);
    }
}
